package zb;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * @author wzby
 * @Date: 2022/8/1 21:13
 */
public class FileStream {
    public static void main(String[] args) {
        //FileOutputStream 文件输出流，主要用来写入内容
        try (FileOutputStream fos = new FileOutputStream("E:\\idea\\java\\ch09\\src\\f\\t.txt", true)) {
            fos.write("hello".getBytes());
            fos.write("java".getBytes());
            fos.write("\n".getBytes());
        } catch (Exception e) {
        }
        //FileInputStream 文件输入流，主要用来读取文件内容
        try(var fis = new FileInputStream("E:\\idea\\java\\ch09\\src\\f\\t.txt")){
            //fis.readAllBytes();
            //fis.read();
            //fis.read(buf);
            //fis.skip(2);
            //System.out.println((char)fis.read());


            fis.skip(2);
            byte [] buf = new byte[3];
            System.out.println(Arrays.toString(buf));
            fis.read(buf);
            System.out.println(Arrays.toString(buf));
            System.out.println(new String(buf));

            //byte [] buf = fis.readAllBytes();
            System.out.println(new String(buf));
        }catch (IOException e){
            throw new RuntimeException(e);
        }
    }
}
